$.ajax({
	url: "https://order.wz1996.wang/wzbg/store/types",
	type: 'get',
	contentType: 'application/json',
	beforeSend: function(request) {
		request.setRequestHeader("token", localStorage.getItem("token"));
	},
	success: function(data) {
		console.log(data);
		if(data.code == "-1") {
			layar(data.msg);
			setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
		}
	},
	error: function(e) {
		errcode(e);
	}
});
function getList() {
	$("#dataTables-example").dataTable().fnDestroy();
	var table = $("#dataTables-example").DataTable({
		ajax: {
			url: "https://order.wz1996.wang/wzbg/openedcity/all",
			type: "get",
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			}
		},
		columns: [{
				data: "cityName"
			},
			{
				data: "cityNameEn"
			},
			{
				data: "imageUrl",
				render: function(data, type, full) {
					return "<img class='citypic' src='" + full.imageUrl + "' />"
				}
			},
			{
				data: "id",
				render: function(data, type, full) {
					return "<a id=" + full.id + " href='../update-city/update-city.html' class='updateCity'>修改</a><a id=" + full.id + " href='javascript:void(0);' style='margin-left:5px' class='deltel'>删除</a>"
				}
			}
		],
		responsive: false,
		bLengthChange: false,
		bSort: false,
		paging: true,
		bFilter: true,
		searching: false,
		bInfo: true,
		bAutoWidth: true,
		"oLanguage": {
			"sLengthMenu": "每页显示 _MENU_ 条记录",
			"sZeroRecords": "抱歉， 没有找到",
			"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
			"sInfoEmpty": "没有数据",
			"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
			"oPaginate": {
				"sFirst": "首页",
				"sPrevious": "前一页",
				"sNext": "后一页",
				"sLast": "尾页"
			},
			"sSearch": "查询条件:",
			"sZeroRecords": "没有检索到数据",
			"sProcessing": "<img src='./loading.gif' />"
		}
	});
}
$("#dataTables-example").on('click', '.deltel', function() {
	var deiId = $(this).attr("id");
	layer.confirm('您确定删除吗？', {
		btn: ['确定', '取消'], //按钮
		offset: '25%'
	}, function(index) {
		$.ajax({
			url: "https://order.wz1996.wang/wzbg/openedcity/remove/" + deiId,
			type: 'DELETE',
			contentType: 'application/json',
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			},
			success: function(data) {
				console.log(data);
				//登录状态
				if(data.code == "1") {
					layar("删除成功");
					getList();
				} else {
					layar(data.msg);
				}
			},
			error: function(e) {
				errcode(e);
			}
		});
	});
});
$(".cancel").on('click', function() {
	$(".delbox").hide();
	$(".bgc").hide();
});
$(".create").on('click', function() {
	window.location.href = '../creat-city/creat-city.html'
});

$("#dataTables-example").on('click', '.updateCity', function() {
	var updateId = $(this).attr("id");
	localStorage.setItem("updateId", updateId);
});